package cn.mavor.day0929;

import java.io.*;
import java.nio.file.*;

public class ReplaceTextInFile {

    public static void main(String[] args) {
        // 定义文件路径
        Path filePath = Paths.get("chaoxian.txt");
        String oldString = "金正恩";
        String newString = "金三胖";

        try {
            // 读取文件内容
            String content = new String(Files.readAllBytes(filePath), "UTF-8");

            // 替换指定字符串
            content = content.replace(oldString, newString);

            // 写入替换后的内容到文件
            Files.write(filePath, content.getBytes("UTF-8"));

            System.out.println("替换完成！");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}